/**
 * Created by zhuyufeng on 2015/12/30.
 */
Ext.define('noticemodel', {
	extend: 'Ext.data.Model',
	fields: [ 'date','class', 'info']
});
var noticeStore = Ext.create('Ext.data.Store', {
	model: 'noticemodel',
	autoLoad: true,
	pageSize: 5,
	proxy: {
		type: 'ajax',
		url : './json/notice',
		reader: {
			type: 'json',
			root: 'rows',
			totalProperty: 'total'
		}
	}
});
var NoticeBoard = Ext.create('Ext.grid.Panel', {
	store: noticeStore,
	columnWidth:1,
	title: '公告栏',
	columns: [
		{
			text: '日期',
			width: 150,
			dataIndex: 'date'
		},
		{
			text: '类型',
			width:150,
			dataIndex: 'class'
		},
		{
			text: '公告信息',
			width:600,
			dataIndex: 'info'
		}
	],
	dockedItems:[
		{
			xtype: 'pagingtoolbar',
			pagesize: '5',
			id: 'noticepage',
			store: noticeStore,
			dock: 'bottom',
			beforePageText: '页数',
			afterPageText: '总共{0}页',
			displayInfo: true,
			displayMsg: '第{0}条到第{1}条,一共{2}条',
			emptyMsg: '没有记录',
			listeners: {
				beforechange: function (toolbar, page) {
				 var	pageData = toolbar.getPageData();
					var currentPage = pageData.currentPage;//获得当前页数
					alert(currentPage);
					Ext.Ajax.request({
						url:'./json/test',
						params:{
							number:currentPage,
							size:'15'
						},
						method:'post',
						success:function(response){
							var data = Ext.decode(response.responseText);
							NoticeBoard.getStore().proxy.url='./json/test';
							NoticeBoard.getStore().loadData(data);
						}
					})
				}
				//change:function()
			}
		}]
});
function loadnotice(){
	var pagingToolbar = Ext.getCmp('noticepage');
	var a = pagingToolbar.getPagingItems();
	var b = pagingToolbar.getPageData().currentPage;
	console.log(a);
	console.log(b);
	console.log(a[4]);
	console.log(a[4].getSubmitValue);
	pagingToolbar.moveNext(
		//alert("dfa")
	);
}
